<template>
    <el-form :model="form" label-width="100px">

        <el-form-item label="名称:" prop="realName">
            <el-input v-model="form.realName" placeholder="请输入" clearable></el-input>
        </el-form-item>
        <el-form-item label="性别:" prop="gender">
            <el-select v-model="form.gender" placeholder="请选择" clearable>
                <el-option v-for="item in sexOptions" :key="item.dictValue" :label="item.dictLabel"
                    :value="item.dictValue">
                </el-option>
            </el-select>
        </el-form-item>
        <el-form-item label="邮箱:" prop="email">
            <el-input v-model="form.email" placeholder="请输入" clearable></el-input>
        </el-form-item>
        <el-form-item label="手机号:" prop="mobile">
            <el-input v-model="form.mobile" placeholder="请输入" clearable></el-input>
        </el-form-item>
        <el-button type="primary" @click="submitClick()">保 存</el-button>
    </el-form>
</template>
<script setup lang="ts">
import { updateUser } from '@/api/sys/orgMemberApi';
import useAppStore from '@/stores/modules/app';
import { useUserStore } from '@/stores/modules/user';
import { ElMessage } from 'element-plus';
import { storeToRefs } from 'pinia';
import { computed, onMounted, ref } from 'vue';
const sexOptions = computed(() => useAppStore().sysDict.sys_sex || []);
const userInfo = storeToRefs(useUserStore()).userInfo;
const form = ref({
    id: '',
    deptId: '',
    username: '',
    realName: '',
    gender: '',
    email: '',
    mobile: '',
})



const submitClick = async () => {
    const data = {
        ...form.value
    }
    const res: apiServerResponse = await updateUser(data);
    if (res.code == 200) {
        ElMessage.success("操作成功！");
        useUserStore().getUserInfo();
    } else {
        ElMessage.error(res.message);
    }
};
const init = () => {
    form.value.id = userInfo.value.userId || "";
    form.value.deptId = userInfo.value.userId || '';
    form.value.username = userInfo.value.username || "";
    form.value.realName = userInfo.value.realName || '';
    form.value.gender = userInfo.value.gender || '';
    form.value.email = userInfo.value.email || '';
    form.value.mobile = userInfo.value.mobile || '';
}

onMounted(() => {
    init();
})
</script>
<style lang="scss" scoped></style>